package com.xyz.study.design_mode.u_proxy.dynamic;

import com.xyz.study.design_mode.u_proxy.dynamic.mode_cglib.EnginnerCGLibProxy;
import com.xyz.study.design_mode.u_proxy.dynamic.mode_invocationhandler.LogHandler;
import com.xyz.study.design_mode.u_proxy.dynamic.mode_invocationhandler.UserManager;
import com.xyz.study.design_mode.u_proxy.dynamic.mode_invocationhandler.UserManagerImpl;

public class DynamicProxyMain {

    public static void main(String[] args){
        // 方式一 InvocationHandler
        LogHandler logHandler = new LogHandler();
        UserManager userManager = (UserManager)logHandler.newProxyInstance(new UserManagerImpl());
        userManager.addUser("1111", "张三");
        userManager.delUser("1111");
        System.out.println("查询结果：" + userManager.findUser("1111"));
        System.out.println("---------------------------------");
        // 方式二 CGLIB
        UserManager userManagerCGLib = (UserManager) new EnginnerCGLibProxy().newProxyInstance(new UserManagerImpl());
        userManagerCGLib.addUser("2222", "李四");
        userManagerCGLib.delUser("2222");
        System.out.println("查询结果：" + userManagerCGLib.findUser("2222"));
    }
}
